export class Tools {
    /**
     * 去掉特殊字符
     * 
     * @static
     * @param {string} str 
     * @returns 
     * 
     * @memberOf Tools
     */
    static DeleteSpecialCharacter(str: string) {
        if (str == null || str == undefined) {
            return "";
        }
        let pattern = new RegExp("[`~!@#$^&*()=|{}':;',[].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
        let rs = "";
        for (let i = 0; i < str.length; i++) {
            rs = rs + str.substr(i, 1).replace(pattern, '');
        }

        str = rs;

        let resultStr = str.replace(/\ +/g, ""); //去掉空格
        resultStr = str.replace(/[ ]/g, "");    //去掉空格
        resultStr = str.replace(/[\r\n]/g, ""); //去掉回车换行

        return resultStr;
    }

    /**
     * 去掉对象中的$$hashkey
     * 
     * @static
     * @param {any} obj 
     * @returns 
     * 
     * @memberOf Tools
     */
    static DeleteHashKey(obj) {
        try {
            let r = JSON.parse(JSON.stringify(obj).replace(new RegExp(/,?\"\$\$hashKey\":\"[A-Za-z0-9+:]+\"/g), ''));
            return r;
        }
        catch (err) {
            return obj;
        }
    }

    /**
     * 删除对象中的pic 图片字段
     * 
     * @static
     * @param {any} obj 
     * @returns 
     * 
     * @memberof Tools
     */
    static DeletePicture(obj) {
        try {
            let r = JSON.parse(JSON.stringify(obj).replace(new RegExp(/,?\"pic\":\"[A-Za-z0-9+:]+\"/g), ''));
            return r;
        }
        catch (err) { 
            return obj;
        }
    }
}